<!--
 * @Author: 刘十三
 * @Date: 2024-02-26 10:37:30
 * @LastEditors: 刘十三
 * @LastEditTime: 2024-02-27 15:51:13
 * @FilePath: \NM-dev-1.3.1\dev\pages\internal\linkage\todo\components\arrangeTaskResult.vue
 * @Description: 任务派发-调查结果
-->

<template>
  <view class="form-main">
    <u-form class="u-form-m" :model="result" :error-type="['border-bottom']" label-width="auto" label-position="top" ref="uForm">
      <u-form-item label="调查情况" prop="checkState" :required="isEdit == 'edit'">
        <u-radio-group v-model="result.checkState" :disabled="isEdit == 'view'">
          <u-radio name="1">存在异常情况</u-radio>
          <u-radio name="0">无异常情况</u-radio>
        </u-radio-group>
      </u-form-item>
      <u-form-item label="调查人" prop="checkPersonName">
        <u-input placeholder="提交时选择" v-model="result.checkPersonName" :disabled="true"></u-input>
      </u-form-item>
      <u-form-item label="调查日期" prop="checkDate" :required="isEdit == 'edit'" :right-icon="isEdit == 'edit' ? 'arrow-right' : ''">
        <u-input placeholder="请选择" v-model="result.checkDate" disabled @click="clickDatekHandle"></u-input>
      </u-form-item>
      <u-form-item label="调查情况说明" prop="checkRemark" :required="isEdit == 'edit'">
        <u-input placeholder="请输入" v-model="result.checkRemark" type="textarea" height="100" :auto-height="true" :disabled="isEdit == 'view'" maxlength="500" />
      </u-form-item>
      <u-form-item label="附件" prop="checkPersonName" :border-bottom="false">
        <view v-if="isEdit == 'view' && fileList.length == 0" style="padding-top: 10px;margin-left: 5px">
          <u-icon name="attach" color="#2979ff" size="28"></u-icon>
          <span style="font-size: 14px;color: #393B3D;">未上传</span>
        </view>
        <m-upload :deletable="isEdit != 'view'" :disabled="isEdit == 'view'" :maxCount="picIds" width="150rpx" height="150rpx" :file-list="fileList" :multiple="true" index="doorwayUpload" :uploadParam="{ fiGroupCode: $FILE_GROUP_TYPE.l_diversification_attr, bizId: result.checkFileId }" upApiUrl="uploadBase64ForApp" ref="filePicUpload" @on-list-change="handleUpdateFile" />
      </u-form-item>
    </u-form>
    <!-- 日历 -->
    <u-picker mode="time" v-model="showTimeVisable" :params="params" :safe-area-inset-bottom="true" @confirm="changeDate"></u-picker>
  </view>
</template>

<script>
import mUpload from "@/components/m-upload.vue";
import commonService from "@/service/common/common.service";

export default {
  components: { mUpload },
  name: "arrangeTaskResult",
  props: {
    isEdit: {
      type: String,
      default: "edit",
    },
  },
  data() {
    return {
      picIds: 10,
      params: {
        year: true,
        month: true,
        day: true,
        hour: false,
        minute: false,
        second: false,
      },
      showTimeVisable: false,
      result: {
        checkState: "", //	调查情况
        checkPersonName: "", //	调查人
        checkDate: "", // 调查日期
        checkRemark: "", // 调查情况说明
        checkFileId: "", // 附件Id
      },
      fileList: [],
      rules: {
        checkState: [
          {
            required: true,
            message: "请选择调查情况",
            trigger: ["blur", "change"],
          },
        ],
        checkDate: [
          {
            required: true,
            message: "请选择调查日期",
            trigger: ["change"],
          },
        ],
        checkRemark: [
          {
            required: true,
            message: "请选择调查情况说明",
            trigger: ["blur", "change"],
          },
        ],
      },
    };
  },
  methods: {
    checkForm() {
      let self = this;
      return new Promise((resolve, reject) => {
        let form = Object.assign({}, self.result);
        self.$refs.uForm.validate((valid) => {
          if (valid) {
            resolve(form);
          } else {
            reject(3);
          }
        });
      });
    },
    handleUpdateFile(list) {
      if (list.length > 0) {
        this.fileList = [...list];
      } else {
        this.fileList = [];
      }
    },
    changeDate(value) {
      this.result.checkDate = value.year + "-" + value.month + "-" + value.day;
      this.$refs.uForm.validate();
      this.showTimeVisable = false;
    },
    clickDatekHandle() {
      if (this.isEdit == "edit") {
        this.showTimeVisable = true;
      }
    },
    getFileList() {
      commonService.goFiles(this.result.checkFileId, this.$FILE_GROUP_TYPE.l_diversification_attr).then((rs) => {
        if (rs.success && rs.code == 200) {
          if (rs.data.length > 0) {
            this.fileList = rs.data.map((item) => {
              return {
                fileId: item.gfiId,
                gfiId: item.gfiId,
              };
            });
          }
        } else {
          this.$u.toast(rs.msg);
        }
      });
    },
  },
  mounted() {
    if (this.isEdit == "edit") {
      this.$refs.uForm.setRules(this.rules);
      this.result.checkPersonName = this.curUser.user.personName;
    }
  },
};
</script>

<style lang="scss" scoped>
.u-form-m {
  padding: 0px 5px;
}
</style>
